package com.lagou.dockerdemo.controller;

import com.lagou.dockerdemo.mapper.StudentMapper;
import com.lagou.dockerdemo.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description
 * @Author ch'ien
 * @Date 2021/8/31 16:09
 **/
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentMapper studentMapper;

    @GetMapping("/save")
    public int save(@RequestParam("name")String name){
        return studentMapper.save(new Student().setName(name));
    }

    @GetMapping("/getById")
    public Student getById(@RequestParam("id")Long id){
        return studentMapper.getById(id);
    }

    @GetMapping("/list")
    public List<Student> list(){
        return studentMapper.getAll();
    }

    @GetMapping("/del")
    public int del(@RequestParam("id")Long id){
        return studentMapper.delById(id);
    }

    @GetMapping("/update")
    public int update(@RequestParam("name")String name, @RequestParam("id")Long id){
        return studentMapper.updateById(new Student().setName(name).setId(id));
    }
}
